﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspLable.Function.Systems;
using nspLable.Function;
using Product;
using nspLable.Manage;
using nspJob;
using System.Text;


public partial class job_Job : System.Web.UI.Page
{
    public string _headstr = "";
    public string _typelike = "";
    public string _footstr = "";
    public string comCount1 = "0";
    public string comCount2 = "0";
    public string comCount3 = "0";
    public int listtype = 1;
    public string _lowertype = "";
    public int typeid = 0;
    public int jobcount = 0;
    public DataTable jobTab = new DataTable();
    protected ArrayList jobArray = new ArrayList();
    public int PageIndex = 1;
    public int PageSize = 10;
    public int pagecount = 1;
    public string PageNav = "";
    public string strUrl = "";
    public string strWhere = " ";
    public string strSelect = " * ";
    public string title = "";
    public string pid = "";
    public string keyword = "";
    public string prevPage = "";
    public int timetype = 0;
    public string nextPage = "";
    public int compID = 0;
    public TJob tjb = new TJob();
    public string readcookies = "";
    public int endtime = 0;
    public int seltype = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (HttpContext.Current.Request.QueryString["type"] != null && HttpContext.Current.Request.QueryString["type"] != "")
            {
                listtype = Convert.ToInt32(HttpContext.Current.Request.QueryString["type"]);
            }
            if (HttpContext.Current.Request.QueryString["id"] != null && HttpContext.Current.Request.QueryString["id"] != "")
            {
                typeid = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
            }
            if (HttpContext.Current.Request.QueryString["timetype"] != null && HttpContext.Current.Request.QueryString["timetype"] != "")
            {
                timetype = Convert.ToInt32(HttpContext.Current.Request.QueryString["timetype"]);
            }
            if (HttpContext.Current.Request.QueryString["pid"] != null)
            {
                pid = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["pid"]);
            }
            if (HttpContext.Current.Request.QueryString["keyword"] != null)
            {
                keyword = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["keyword"]);
            }
            if (HttpContext.Current.Request.QueryString["compID"] != null)
            {
                compID = Convert.ToInt32(HttpContext.Current.Request.QueryString["compID"]);
            }
            if (HttpContext.Current.Request.QueryString["endtime"] != null && HttpContext.Current.Request.QueryString["endtime"] != "")
            {
                endtime = Convert.ToInt32(HttpContext.Current.Request.QueryString["endtime"]);
            }
            if (HttpContext.Current.Request.QueryString["seltype"] != null && HttpContext.Current.Request.QueryString["seltype"] != "")
            {
                seltype = Convert.ToInt32(HttpContext.Current.Request.QueryString["seltype"]);
            }

            strUrl = Base.BasePage.Config.WebURL + "job/jobtrade" + Base.BasePage.Config.Rewrite + "?type=" + listtype + "&id=" + typeid + "";
            if (listtype == 1)
            {
                strSelect = " select [U_UserInfo].LoginName,[U_UserInfo].CompanyName,[U_UserInfo].Summary,[C_Job].TypeID,[C_Job].ID,[C_JobType].TypeName,[C_Job].Position,[C_Job].Count,[C_Job].Degree ,[C_Job].SalaryLevel,[C_Job].Sex,[C_Job].AddDate,[C_Job].EndDate,[C_Job].Experience,[C_Job].WorkTemper,[C_Job].Address from [C_Job],[C_JobType],[U_UserInfo] ";
                strWhere = " [C_Job].TypeID=[C_JobType].ID and (datediff(hh,C_Job.EndDate,getdate())<0) AND [C_Job].Verify=1 AND [C_Job].UserID=[U_UserInfo].UserID ";

             
                if (typeid != 0)
                {
                    strWhere += " and [C_Job].TypeID=" + typeid;
                }
                if (keyword != "")
                {
                    if (seltype == 0||seltype==1)
                    {
                        strWhere += " and [C_Job].Position like '%" + keyword + "%'";
                    }
                    if (seltype == 2)
                    {
                        strWhere += " and [U_UserInfo].CompanyName like '%" + keyword + "%'";
                    }

                    strUrl += "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
                }
                if (pid != "" && pid != "请选择省份")
                {
                    strWhere += " and  [C_Job].Address = '" + pid + "'";
                    strUrl += "&pid=" + System.Web.HttpUtility.UrlEncode(pid);
                }
                if (compID != 0)
                {
                    strWhere += " and [C_Job].UserID=" + compID;
                    strUrl += "&compID=" + compID;
                }
                if (timetype != 0)
                {
                    switch (timetype)
                    { 
                        case 1:
                            strWhere += " and   (DATEDIFF(year, C_Job.AddDate, GETDATE()) <= 1)";
                            break;
                        case 2:
                            strWhere += " and   (DATEDIFF(month, C_Job.AddDate, GETDATE()) <= 1)";
                            break;
                        case 3:
                            strWhere += " and   (DATEDIFF(day, C_Job.AddDate, GETDATE()) <= 17)";
                            break;
                        case 4:
                            strWhere += " and   (DATEDIFF(day, C_Job.AddDate, GETDATE()) <= 17)";
                            break;
                        case 5:
                            strWhere += " and   (DATEDIFF(day, C_Job.AddDate, GETDATE()) <= 2)";
                            break;
                        case 6:
                            strWhere += " and   (DATEDIFF(day, C_Job.AddDate, GETDATE()) = 0)";
                            break;
                    }
                    strUrl += "&timetype=" + timetype;
                }
                if (endtime != 0)
                {
                    switch (endtime)
                    {
                        case 1:
                            strWhere += " and   (DATEDIFF(year, C_Job.EndDate, GETDATE()) <= 1)";
                            break;
                        case 2:
                            strWhere += " and   (DATEDIFF(month, C_Job.EndDate, GETDATE()) <= 1)";
                            break;
                        case 3:
                            strWhere += " and   (DATEDIFF(day, C_Job.EndDate, GETDATE()) <= 17)";
                            break;
                        case 4:
                            strWhere += " and   (DATEDIFF(day, C_Job.EndDate, GETDATE()) <= 17)";
                            break;
                        case 5:
                            strWhere += " and   (DATEDIFF(day, C_Job.EndDate, GETDATE()) <= 2)";
                            break;
                        case 6:
                            strWhere += " and   (DATEDIFF(day, C_Job.EndDate, GETDATE()) = 0)";
                            break;
                    }
                    strUrl += "&endtime=" + endtime;
                }
            }
            if (listtype == 2)
            {
                strSelect = " select [U_Resume].ID,[C_JobType].TypeName,[U_Resume].WantPosition,[U_Resume].Photo,[U_Resume].Sex,[U_Resume].ContactAddress,[U_Resume].AddDate,[U_Resume].txtwork,[U_Resume].HighestEducation,[U_Resume].GraduateSchool,[U_Resume].WantAddress,[U_Resume].WantSalary,[U_Resume].Name from [U_Resume],[C_JobType]";
                strWhere = " [U_Resume].TalentType=[C_JobType].ID  and  [U_Resume].Verify=1  ";
                if (pid != "" && pid != "请选择省份")
                {
                    strWhere += " and  [U_Resume].WantAddress = '" + pid + "'";
                    strUrl += "&pid=" + System.Web.HttpUtility.UrlEncode(pid);
                }
                if (typeid != 0)
                {
                    strWhere += " and [U_Resume].TalentType=" + typeid;
                }
                if (keyword != "")
                {
                    if (seltype == 0 || seltype == 1)
                    {
                        strWhere += " and [U_Resume].WantPosition like '%" + keyword + "%'";
                    }
                    if (seltype == 2)
                    {
                        strWhere += " and [U_Resume].Name like '%" + keyword + "%'";
                        
                    }

                    strUrl += "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
                }
                if (timetype != 0)
                {
                    switch (timetype)
                    {
                        case 1:
                            strWhere += " and   (DATEDIFF(year, U_Resume.AddDate, GETDATE()) <= 1)";
                            break;
                        case 2:
                            strWhere += " and   (DATEDIFF(month, U_Resume.AddDate, GETDATE()) <= 1)";
                            break;
                        case 3:
                            strWhere += " and   (DATEDIFF(day, U_Resume.AddDate, GETDATE()) <= 17)";
                            break;
                        case 4:
                            strWhere += " and   (DATEDIFF(day, U_Resume.AddDate, GETDATE()) <= 17)";
                            break;
                        case 5:
                            strWhere += " and   (DATEDIFF(day, U_Resume.AddDate, GETDATE()) <= 2)";
                            break;
                        case 6:
                            strWhere += " and   (DATEDIFF(day, U_Resume.AddDate, GETDATE()) = 0)";
                            break;
                    }
                    strUrl += "&timetype=" + timetype;
                }
            }
            strUrl += "&Page=";
            getHead();
            getFoot();
            Bind();
            jobBind();
            if (listtype == 1)
            {
                title = "招聘列表";
            }
            if (listtype == 2)
            {
                title = "求职列表";
            }

            if (PageIndex == 1)
            {
                prevPage = strUrl + 1;
            }
            if (PageIndex > 1)
            {
                prevPage = strUrl + (PageIndex - 1);
            }

            if (PageIndex == pagecount)
            {
                nextPage = strUrl + PageIndex;
            }
            if (PageIndex < pagecount)
            {
                nextPage = strUrl + (PageIndex + 1);
            }
            readcookies = readcookie();
        }
    }
    private void Bind()
    {
        Rjob rjb = new Rjob();
        jobTab = rjb.GetJoblist(strSelect, strWhere);
        _lowertype = rjb.lowerType(typeid.ToString(),listtype);
        _typelike = rjb.TypeLink(typeid.ToString());
        comCount1 = rjb.GetcompanyCount("").Rows.Count.ToString();
        comCount2 = rjb.GetcompanyCount(" Verify=1 ").Rows.Count.ToString();
        comCount3 = rjb.GetcompanyCount(" (datediff(dd,RegDate,getdate()))=0 ").Rows.Count.ToString();
    }
    private void jobBind()
    {
        jobArray.Clear();
        jobArray.AddRange(jobTab.Rows);    //每页品牌列表
        jobcount = jobArray.Count;
        //获取总页数
        pagecount = jobcount % PageSize == 0 ? jobcount / PageSize : jobcount / PageSize + 1;
        if (pagecount == 0) pagecount = 1;
        PageIndex = PageIndex < 1 ? 1 : PageIndex;
        PageIndex = PageIndex > pagecount ? pagecount : PageIndex;
        if (listtype == 1)
        {
            PageNav = Pagination.GoToPager(PageIndex, PageSize, strUrl, strWhere, "  [C_Job],[C_JobType],[U_UserInfo] ");
        }
        if (listtype == 2)
        {
            PageNav = Pagination.GoToPager(PageIndex, PageSize, strUrl, strWhere, "  [U_Resume],[C_JobType] ");
        }
        int pcount = PageSize;
        if (PageIndex * PageSize > jobcount) pcount = PageSize - (PageIndex * PageSize - jobcount);
        jobArray = jobArray.GetRange((PageIndex - 1) * PageSize, pcount);
    }
    private void getHead()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站头部");
        if (Temp.Info == null || Temp.Info == "")
            _headstr = "";
        else
            _headstr = Temp.Info.ToString();
        _headstr = _headstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);
        _headstr = _headstr.Replace("{PB_收录企业}", comCount1);
        _headstr = _headstr.Replace("{PB_审核通过企业}", comCount2);
        _headstr = _headstr.Replace("{PB_今日收录}", comCount3);
    }
    private void getFoot()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站底部");
        if (Temp.Info == null || Temp.Info == "")
            _footstr = "";
        else
            _footstr = Temp.Info.ToString();
        _footstr = _footstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);
    }
    //最新浏览过的招聘信息
    protected string readcookie()
    {
        StringBuilder sb = new StringBuilder();
        if (Base.BasePage.GetCookie("readjob") != null)
        {
            string minolist = Base.BasePage.GetCookie("readjob").ToString();
            if (minolist != "")
            {
                string[] minojob = minolist.Split(',');
                int cnt = 0;
                for (int i = minojob.Length - 1; i >= 0; i--)
                {
                    if (Base.Common.CheckNum(minojob[i].ToString()))
                    {

                        Rjob rjb = new Rjob();
                        tjb = rjb.GateItem(int.Parse(minojob[i], 0));
                        if (tjb != null)
                        {
                            sb.Append("<li>▪&nbsp;<a title=\"\" target=\"_blank\" href=\"" + Base.BasePage.Config.WebURL + "JobShow-" + int.Parse(minojob[i]) + Base.BasePage.Config.Rewrite + "\">" + Function.GetString(tjb.Position, 15) + "</a></li>");
                        }
                        if (cnt >= 10) break;
                    }

                }
            }
        }
        return sb.ToString();
    }
}